<template>
	<view class="index-content">
		<view class="root">
			<ren-dropdown-filter :height="50" :filterData='filterData' :defaultIndex='defaultIndex'
			@onSelected='onSelected'></ren-dropdown-filter>
		</view>
		<view class="body">
			<block v-for="(item,index) in list" :key="index">
				<paper-list :item="item" :index="index"></paper-list>
			</block>
			<uni-load-more :status="status"></uni-load-more>
			<my-fab-top :scrollTop="scrollTop"></my-fab-top>
		</view>
	</view>
</template>

<script>
	var _self, loginRes;
	import RenDropdownFilter from '@/components/ren-dropdown-filter/ren-dropdown-filter.vue'
	import paperList from "../../components/paper/paper-list.vue";
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	import myFabTop from "@/components/wppeng-top/wppeng-top.vue"
	export default {
		components:{
			paperList,uniLoadMore,myFabTop,RenDropdownFilter
		},
		data() {
			return {
				scrollTop:0,
				swiperheight:500,
				list:[],
				pageSize:15,
				currPage:1,
				total:0,
				status:'more',
				filterData:[
					[{ text: '全部状态', value: '' }, { text: '进行中', value: '1' }, { text: '已完成', value: '0' }],
					[{ text: '全部年份', value: '' }, { text: '2023', value: '2023' }, { text: '2022', value: '2022' }]
				],
				defaultIndex:[1,0],
				progress:'1',
				year:''
			}
		},
		//监听页面滚动
		onPageScroll(res){
			this.scrollTop=res.scrollTop
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.pageSize=10
			this.currPage=1
			this.getData();
		},
		onReachBottom() {
			this.loadmore();
		},
		// 实现小程序分享
		onShareAppMessage(){
		} ,
		onLoad() {
			// _self = this;
			loginRes = this.checkLogin('../index/index', '2');
			if(!loginRes){return false;}

			this.getData()
			uni.getSystemInfo({
				success: (res)=> {
					let height=res.windowHeight-uni.upx2px(100)
					this.swiperheight=height;
				}
			});
		},
		onShow() {
			// this.pageSize=10
			// this.currPage=1
			// this.getData();
		},
		onHide(){

		},
		onUnload() {

		},
		methods: {
			onSelected(res){
				console.log(res,999)
				this.progress=res[0][0]['value']
				this.year=res[1][0]['value']
				console.log(this.progress,this.year,777)
				this.pageSize=10
				this.currPage=1
				this.getData();
			},
			// 上拉加载
			loadmore(){
				if(this.total<=this.pageSize*this.currPage){ return; }
				this.currPage++
				// 修改状态
				this.status='loading';
				// 获取数据
				this.getData()
			},
			async getData(){
				uni.showLoading({title:""});
				let [err,result]=await this.$http.post("/project/listPage",{
					pageSize:this.pageSize,
					pageNum:this.currPage,
					param:{
						status:this.progress,
						year:this.year
					}
				})
				let {data:res}=result
				console.log(res.data,666)
				if (!this.$http.errorCheck(err,res)) {
					uni.hideLoading();
					return
				}
				if(res.code!=200){
					uni.showToast({ title:res.message,icon:"none"});
					return
				}
				this.total=res.data.total
				if(this.currPage>1){
					this.list=[...this.list,...res.data.records]
					if(this.total<this.currPage*this.pageSize){
						this.status="noMore";
					}else{
						this.status="more";
					}
					
				}else{
					this.list=res.data.records
				}
				uni.hideLoading();
				// 关闭下拉刷新
				uni.stopPullDownRefresh();
			},
		},
	}
</script>

<style lang="less" scoped>
.body{
	padding-top: 80rpx;
}

</style>
